//
//  MPCActionSheetC2Cell.m
//  Pods
//
//  Created by macRong on 2017/8/30.
//
//

#import "MPCActionSheetC2Cell.h"
#import "MPCActionSheetDefines.h"

@interface MPCActionSheetC2Cell()

/**
 *  Highlighted View.
 */
@property (nonatomic, weak) UIView      *highlightedView;

@property (nonatomic, weak) UIImageView *imageView_left;

@end


@implementation MPCActionSheetC2Cell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.clipsToBounds = YES;
        self.backgroundColor = [UIColor clearColor];
        
        // 初始化界面
        [self initViews];
    }
    
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
}

- (void)initViews
{
    UIView *highlightedView  = [[UIView alloc] init];
    highlightedView.backgroundColor = self.cellSeparatorColor;
    highlightedView.clipsToBounds   = YES;
    highlightedView.hidden          = YES;
    [self.contentView addSubview:highlightedView];
    self.highlightedView = highlightedView;
    [highlightedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.adjustsFontSizeToFitWidth = YES;
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(60.0f);
        make.right.top.bottom.equalTo(self.contentView);
    }];
    
    UIView *lineView  = [[UIView alloc] init];
    lineView.backgroundColor = self.cellSeparatorColor;
    lineView.contentMode   = UIViewContentModeBottom;
    lineView.clipsToBounds = YES;
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.right.bottom.equalTo(self.contentView);
        make.height.equalTo(@0.5f);
    }];
    
    UIImageView *imageView = [[UIImageView alloc]init];
    [self.contentView addSubview:imageView];
    self.imageView_left = imageView;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20.0f, 20.0f));
        make.left.equalTo(self.contentView.mas_left).offset(20.0f);
        make.top.equalTo(self.contentView.mas_top).offset(14.5f);
    }];
}

- (void)setImageName:(NSString *)imageName
{
    if (_imageName != imageName)
    {
        _imageName = imageName;

        UIImage *image = [UIImage imageNamed:imageName];
        self.imageView_left.image = image;
        [self.imageView_left mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(image.size);
        }];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    
}

- (void)setCellSeparatorColor:(UIColor *)cellSeparatorColor
{
    _cellSeparatorColor = cellSeparatorColor;
    
    self.highlightedView.backgroundColor = cellSeparatorColor;
    self.lineView.backgroundColor        = cellSeparatorColor;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
//    if (self.tag == MPC_ACTION_SHEET_CELL_HIDDE_LINE_TAG)
//    {
//        self.lineView.hidden = YES;
//    }
//    else
//    {
//        self.lineView.hidden = highlighted;
//    }
    
    self.highlightedView.hidden = !highlighted;
}


@end
